<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>

<link rel="stylesheet" type="text/css" href="<%=path %>/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=path %>/easyui/themes/icon.css">
	<script type="text/javascript" src="<%=path %>/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="<%=path %>/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=path %>/easyui/datagrid-detailview.js"></script>
	<script type="text/javascript" src="<%=path %>/easyui/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="<%=path %>/res/js/CRUD.js"></script>
	
	<link href="<%=path %>/uploadify/uploadify.css" type="text/css" rel="stylesheet" />
	<script src="<%=path %>/uploadify/jquery.uploadify.min.js" type="text/javascript" ></script>
	
	<script type="text/javascript" src="<%=path %>/res/autocomplete/jquery.bigautocomplete.js"></script>
	<link rel="stylesheet" href="<%=path %>/res/autocomplete/jquery.bigautocomplete.css" type="text/css" />

<script type="text/javascript">

function doSearch(){ 
	var cName = $('#syllabusName').val();
	//alert(cName);
	if(cName == ''){
		$.messager.alert('提示', '请输入查询内容！', 'info');
		//$('#dg').datagrid('load');
	}
    $('#dg').datagrid('load',{  
    	syllabusName: cName  
    });  
}

$(function() {
	
	$('#dg').datagrid({    
	    view: detailview,    
	    detailFormatter:function(index,row){    
	        return '<div "><table id="ddv-' + index + '"></table></div>';    
	    },    
	    onExpandRow: function(index,row){    
	        $('#ddv-'+index).datagrid({    
	            url:'getdetail/'+row.id,    
	            fitColumns:true,    
	            singleSelect:true,    
	            rownumbers:true,    
	            loadMsg:'',    
	            height:'auto',    
	            columns:[[    
	                {field:'fileName',title:'名称',align:'center',width:100},    
	                {field:'fileSize',title:'文件大小(KB)',align:'center',width:100},   
	                {field:'tg',title:'通过',align:'center',width:200,formatter:tgFun}    
	            ]],    
	            onResize:function(){    
	                $('#dg').datagrid('fixDetailRowHeight',index);    
	            },    
	            onLoadSuccess:function(){    
	                setTimeout(function(){    
	                    $('#dg').datagrid('fixDetailRowHeight',index);    
	                },0);    
	            }    
	        });    
	        $('#dg').datagrid('fixDetailRowHeight',index);    
	    }    
	}); 
	
	$("#kcmc").bigAutocomplete({
		width:180,
		url:'combox',
		callback:function(data){
			//alert(data.title);
			$("#kcdm").val(data.result);
		}
	});
	
	$("#merge_kcmc").bigAutocomplete({
		width:180,
		url:'combox',
		callback:function(data){
			$("#merge_kcdm").val(data.result);
		}
	});
	
	$('#file_upload').uploadify({
		'buttonText':'文件浏览...',
		'queueSizeLimit':1, 
		'auto':false, 
		'swf': '<%=path %>/uploadify/uploadify.swf',
		'uploader':'<%=path %>/common/upload;jsessionid=<%=request.getSession().getId()%>',
		'fileObjName' : 'file_upload',
		'fileSizeLimit' : '5000KB',
		'fileTypeDesc' : 'Files',
		'fileTypeExts' : ' *.doc;*.docx;*.pdf;',
		'onUploadSuccess' : function(file, data, response) {
			//alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data); 
			var strData = $.parseJSON(data);
			//alert(strData.o.fileName);
			var node = createAttach(strData.o);
			//alert(node);
			$('#uploaded-attach').find('tbody').append(node);
		} 
	}); 
	$('#upload').click(function(){
		$('#file_upload').uploadify('upload','*');
	});
	
	$('#uploaded-attach').on('click','.pn-opt-delete',function(){
		var ad = this;
		///alert("111");
		$(ad).parent().parent().remove();
		
	});
	
});

function createAttach(attach){
	var node = "<tr>";
	
	node += "<td>" + attach.fileName + "</td>";
	//node += "<td>" + attach.fileSize + "KB</td>";
	node += "<td><a href='#' class='pn-opt-delete' title=''>删除附件</a></td>";
	//node += "<input type='hidden' name='filename' value='" + attach.fileName + "' />";
	//node += "<input type='hidden' name='link' value='" + attach.filePath + "' />";
	node += "<input type='hidden' name='attachId' value='" + attach.id + "' />";
	node += "</tr>";
	return node;
}

function linkFun(value,row,index){
	if(row.fileName == null){
		return '';
	}
	var link = "<a href='<%=path %>"+ row.filePath +"'>" + row.fileName + "</a>";
	return link;
}

/**
 * 设置通过状态，-1不通过，0审核中，1通过
 */
function tgFun(value,row,index){
	var str = "";
	var link = "";
	var tg = row.tg;
	if(tg == -1){
		str = '不通过';
		link = "<span style='color:red'>不通过</span><shiro:hasRole name='admin'>&nbsp;<a href='#'>审核</a></shiro:hasRole>";
	}else if(tg == 0){
		str = '审核中';
		link = "<span style='color:red'>审核中</span>";
	}else if(tg == 1){
		str = '通过';
		link = "<span style='color:blue'>通过</span>";
		link += "  <a href='<%=path %>"+ row.filePath +"'>" + '下载' + "</a>";
	}
	return link;
}

</script>
</head>
<body>
<table id="dg" class="easyui-datagrid"
		data-options="url:'<%=path %>/syllabus/all',title:'大纲列表',
		fitColumns:true,singleSelect:true,nowrap: false,fit: true,iconCls:'icon-edit',
		idField:'id',singleSelect:true,pagination:true,rownumbers:true,
		frozenColumns:[[{field:'ck',checkbox:true}]],
		toolbar: '#tb'">
		<thead>
			<tr><shiro:hasRole name=""></shiro:hasRole>
				<th data-options="field:'id',width:50,align:'center'">ID</th>
				<th data-options="field:'kcdm',width:100,align:'center'">课程代码</th>
				<th data-options="field:'kcmc',width:200,align:'center'">课程中文名称</th>
				<th data-options="field:'gxsj',width:100,align:'center'">更新时间</th>
				<!-- 
				<th data-options="field:'filename',width:100,align:'center',formatter:linkFun">大纲链接</th>
				 -->
			</tr>
		</thead>
	</table>
	
	<div id="tb">
		<table style="width:100%;cellpadding:0; cellspacing:0">
			<tr>
				<td style="padding-left:2px">
					<shiro:hasRole name="admin">
					<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="newObject('#dlg','#fm','合并大纲','save')">合并大纲</a>
					</shiro:hasRole>
					<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="editObject('#dg','#upload_dlg','#upload_fm','上传大纲','')">上传大纲</a>
				</td>
				<td><div class="pagination-btn-separator"></div></td>
				<td>
					<label for="syllabusName">大纲名称：</label><input type="text" id="syllabusName">
					<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch()">查询</a>
				</td>
			</tr>
		</table>
	</div>
	
	<!-- 表单 start -->
	<div id="dlg" class="easyui-dialog" style="width:400px;height:300px;padding:10px 20px"    
	        data-options="closed:true, buttons:'#dlg-buttons'">   
			<form id="fm" method="post">
				<div><span>合并大纲信息</span></div> 
				<table style="padding-top: 10px;text-align:center;">
					<tr>
						<td>大纲名称：</td>
						<td>
							<input id="kcmc" class="easyui-validatebox" name="kcmc" data-options="required:true" />
							<input type="hidden" name="id" value=""/>	
						</td>
					</tr>
					<tr>
						<td>大纲代码：</td>
						<td><input id="kcdm" class="easyui-validatebox" type="text"
							name="kcdm" data-options="required:true"></input></td>
					</tr>
					<tr>
						<td>合并大纲名称：</td>
						<td><input id="merge_kcmc" class="easyui-validatebox" type="text"
							name="merge_kcmc" data-options="required:true"></input></td>
					</tr>
					<tr>
						<td>合并大纲代码：</td>
						<td><input id="merge_kcdm" class="easyui-validatebox" type="text"
							name="merge_kcdm" data-options="required:true"></input></td>
					</tr>
					
				</table>
			</form>
	</div>
	<div id="dlg-buttons">    
	    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveObject('#fm','#dlg','#dg','merge')">合并</a>    
	    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">取消</a>    
	</div>  
	<!-- 表单 end --> 
	<!-- 上传大纲  start -->
	<div id="upload_dlg" class="easyui-dialog" style="width:400px;height:300px;padding:10px 20px"    
	        data-options="closed:true, buttons:'#upload_dlg-buttons'">  
	        <form id="upload_fm" method="post">
	        	<table style="padding-top: 10px;text-align:center;">
					<tr>
						<td>大纲名称：</td>
						<td><input class="easyui-validatebox" type="text"
							name="kcmc" data-options="required:true"></input>
							<input type="hidden" name="id">
						</td>
					</tr>
					<tr>
						<td>大纲代码：</td>
						<td><input class="easyui-validatebox" type="text"
							name="kcdm" data-options="required:true"></input></td>
					</tr>
					<tr>
						<td>上传文件：</td>
						<td>
							<input id="file_upload" name="file_upload" type="file">
							<input id="upload" class="upload-button" type="button" onclick="" value="上传">
						</td>
					</tr>
					<tr>
						<td>附件:</td>
						<td colspan="2">
							<table id="uploaded-attach" style="width:100%; cellpadding:0">
								<thead>
									<tr>
										<td width="50%">文件名</td>
										<td width="50%">操作</td>
									</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
						</td>
					</tr>
				</table>
	        </form>
	</div>
	<div id="upload_dlg-buttons">    
	    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveObject('#upload_fm','#upload_dlg','#dg','save')">提交</a>    
	    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#upload_dlg').dialog('close')">取消</a>    
	</div>
	<!-- 上传大纲 end -->
</body>
</html>